package top.dancun.easteacher.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.dancun.common.entity.UserEntity;
import top.dancun.common.utils.PageUtils;
import top.dancun.common.utils.R;
import top.dancun.easteacher.entity.TeacherEntity;
import top.dancun.easteacher.feign.SysFeign;
import top.dancun.easteacher.feign.service.SysFeignService;
import top.dancun.easteacher.service.TeacherService;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 
 *
 * @author dancun
 * @email message@dancun.top
 * @date 2022-10-17 09:34:10
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController extends AbstractController{
    @Autowired
    private TeacherService teacherService;



    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("easteacher:teacher:list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = teacherService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/listbyids")
//    @RequiresPermissions("easteacher:teacher:list")
    public R listByIds(@RequestBody List<String> ids){
        List<TeacherEntity> list = teacherService.lambdaQuery().in(TeacherEntity::getTid,ids).list();

        return R.ok().put("data", list);
    }

    @RequestMapping("/search")
//    @RequiresPermissions("easteacher:teacher:search")
    public R search(@RequestBody(required = false) Map<String, String> params){

        List<TeacherEntity> teachers = teacherService.search(params);
        return R.ok().put("data", teachers);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{tid}")
    @RequiresPermissions("easteacher:teacher:info")
    public R info(@PathVariable("tid") String tid){
		TeacherEntity teacher = teacherService.getById(tid);

        return R.ok().put("teacher", teacher);
    }
    @RequestMapping("/info")
    public R myInfo(){
        String tid = getUserId();
        TeacherEntity teacher = teacherService.getById(tid);

        return R.ok().put("teacher", teacher);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("easteacher:teacher:save")
    public R save(@RequestBody TeacherEntity teacher){

		teacherService.save(teacher);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("easteacher:teacher:update")
    public R update(@RequestBody TeacherEntity teacher){
		teacherService.updateById(teacher);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("easteacher:teacher:delete")
    public R delete(@RequestBody String[] tids){
		teacherService.removeByIds(Arrays.asList(tids));

        return R.ok();
    }

}
